package org.example.springchatroom.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.springchatroom.mapper.MessageMapper;
import org.example.springchatroom.model.Message;
import org.example.springchatroom.model.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 九转苍翎
 * Date: 2025/9/10
 * Time: 22:43
 */
@RestController
@RequestMapping("/content")
@Slf4j
public class MessageController {
    @Autowired
    private MessageMapper messageMapper;

    @RequestMapping(value = "/getMessageBySessionId",method = RequestMethod.GET)
    public Result<List<Message>> getMessageBySessionId(Integer sessionId) {
        log.info("getMessageBySessionId接收参数:sessionId={}", sessionId);
        List<Message> messageList = messageMapper.getMessageBySessionId(sessionId);
        Collections.reverse(messageList);
        return Result.success(messageList);
    }
}
